/** 根路由: / */
export const ROOT_ROUTE: AuthRoute.Route = {
  name: "root",
  path: "/",
  redirect: import.meta.env.VITE_ROUTE_HOME_PATH,
  meta: {
    title: "Root",
  },
};

/** 404 */
export const NOT_FOUND_ROUTE: AuthRoute.Route = {
  name: "not-found",
  path: "/:pathMatch(.*)*",
  redirect: "/404",
  meta: {
    title: "未找到",
  },
};

/** 固定的路由 */
export const basicRoutes: AuthRoute.Route[] = [
  ROOT_ROUTE,
  {
    name: "login",
    path: import.meta.env.VITE_LOGIN_PATH,
    component: import("@/views/_builtin/login/index.vue"),
    meta: {
      title: "登录",
    },
  },
  {
    name: "403",
    path: "/403",
    component: import("@/views/_builtin/403/index.vue"),
    meta: {
      title: "无权限",
    },
  },
  {
    name: "404",
    path: "/404",
    component: import("@/views/_builtin/404/index.vue"),
    meta: {
      title: "未找到",
    },
  },
  {
    name: "500",
    path: "/500",
    component: import("@/views/_builtin/500/index.vue"),
    meta: {
      title: "服务器错误",
    },
  },
];

const getRouteName = (route: AuthRoute.Route) => {
  const names = [route.name];
  if (route.children && route.children.length) {
    names.push(...route.children.flatMap((item) => getRouteName(item)));
  }
  return names;
};
export const basicRoutesName = basicRoutes.flatMap((route) =>
  getRouteName(route)
);

const getRoutePath = (route: AuthRoute.Route) => {
  const paths = [route.path];
  if (route.children && route.children.length) {
    paths.push(...route.children.flatMap((item) => getRoutePath(item)));
  }
  return paths;
};
export const basicRoutesPath = basicRoutes.flatMap((route) =>
  getRoutePath(route)
);
